package com.dems.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dems.dao.dataobject.CfgDeviceInfo;
import com.dems.dao.dataobject.User;
import com.dems.dao.mapper.la.CfgDeviceInfoMapper;
import com.dems.domain.DeviceInfoReqVO;
import com.dems.service.CfgDeviceInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class CfgDeviceInfoServiceImpl implements CfgDeviceInfoService {

    @Autowired
    private CfgDeviceInfoMapper deviceInfoMapper;

    @Override
    public Page queryDeviceInfoList(DeviceInfoReqVO deviceInfoReqVO) {
        Page page = new Page(deviceInfoReqVO.getPageNum(), deviceInfoReqVO.getPageSize());
        CfgDeviceInfo deviceInfo = new CfgDeviceInfo();
        BeanUtils.copyProperties(deviceInfoReqVO, deviceInfo);
        return deviceInfoMapper.queryDeviceInfoList(page, deviceInfo);
    }

    @Override
    public int batchCreateDeviceInfo(List<CfgDeviceInfo> cfgDeviceInfoList, User user) {
        for(CfgDeviceInfo cfgDeviceInfo : cfgDeviceInfoList){
            cfgDeviceInfo.setCreateTime(new Date());
            cfgDeviceInfo.setCreateUserId(user.getUserId());
            deviceInfoMapper.insertSelective(cfgDeviceInfo);
        }
        return 0;
    }

    @Override
    public int createDeviceInfo(CfgDeviceInfo cfgDeviceInfo, User user) {
        cfgDeviceInfo.setCreateUserId(user.getUserId());
        cfgDeviceInfo.setCreateTime(new Date());
        return deviceInfoMapper.insertSelective(cfgDeviceInfo);
    }

    @Override
    public int updateDeviceInfo(CfgDeviceInfo cfgDeviceInfo, User user) {
        cfgDeviceInfo.setUpdateUserId(user.getUserId());
        cfgDeviceInfo.setUpdateTime(new Date());
        return deviceInfoMapper.updateByPrimaryKeySelective(cfgDeviceInfo);
    }
}
